package com.example.liang.basamovie.adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.liang.basamovie.R;
import com.example.liang.basamovie.activity.WebActivity;
import com.example.liang.basamovie.bean.Recommend4;
import com.example.liang.basamovie.utils.ImageLoaderUtils;
import java.util.List;
public class PastSelectAdapter extends RecyclerView.Adapter<PastSelectAdapter.Myviewholder> {
    Context context;
    List<Recommend4> data;

    public PastSelectAdapter(Context context, List<Recommend4> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public Myviewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.pastselect_up_layout, parent, false);
        return new Myviewholder(view);
    }
    @Override
    public void onBindViewHolder(Myviewholder holder, int position) {
        final Recommend4 recommend4 = data.get(position);
        holder.title.setText(recommend4.getTitle());
        holder.context.setText(recommend4.getDescription());
        ImageLoaderUtils.setimage(context,recommend4.getImage_url(),holder.upimage);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,WebActivity.class);
                intent.putExtra("url",recommend4.getArticleContentUrl());
                intent.putExtra("title",recommend4.getTitle());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class Myviewholder extends RecyclerView.ViewHolder{
        ImageView upimage;
        TextView title,context;
        public Myviewholder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.pastSelect_title);
            context= (TextView) itemView.findViewById(R.id.pastSelect__context);
            upimage=(ImageView)itemView.findViewById(R.id.pastSelect__image);
        }
    }



}
